#include "MainTank.h"

MainTank::MainTank()
{
	m_x=100;
	m_y=100;
	m_step=2;
	m_dir=UP;
}

void MainTank::DrawTankbody(int style)
{
	fillrectangle(m_x-4,m_y-4,m_x+4,m_y+4);
	if(style==1)
	{
		fillrectangle(m_x-6,m_y-6,m_x-4,m_y+6);
		fillrectangle(m_x+4,m_y-6,m_x+6,m_y+6);
	}
	else
	{
		fillrectangle(m_x-6,m_y-6,m_x+6,m_y-4);
		fillrectangle(m_x-6,m_y+4,m_x+6,m_y+6);
	}
}

void MainTank::Display()
{
	switch(m_dir)
	{
		case UP:
			DrawTankbody(1);
			line(m_x,m_y-8,m_x,m_y-4);
			break;
		case DOWN:
			DrawTankbody(1);
			line(m_x,m_y+8,m_x,m_y+4);
			break;
		case LEFT:
			DrawTankbody(0);
			line(m_x-8,m_y,m_x-4,m_y);
			break;
		case RIGHT:
			DrawTankbody(0);
			line(m_x+4,m_y,m_x+8,m_y);
			break;
		default:
			break;
	}

}

void MainTank::Move()
{
	if(m_x>SCREEN_WIDTH)  m_x=1;
	if(m_x<0) m_x=SCREEN_WIDTH-1;
	if(m_y<0) m_y=SCREEN_HEIGHT-1;
	if(m_y>SCREEN_HEIGHT) m_y=1;
		
	switch(m_dir)
	{
		case UP:
			m_y-=m_step;
			break;
		case DOWN:
			m_y+=m_step;
			break;
		case LEFT:
			m_x-=m_step;
			break;
		case RIGHT:
			m_x+=m_step;
		default:
			break;

	}
}